<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('曲目列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>曲目名称：</label>
                                <input type="text" name="songName"/>
                                <input type="hidden" name="bookId" id="bookId" th:value="${bookId}"/>
                                <input type="hidden" name="preidId" id="preidId" th:value="${preidId}"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:song:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:song:remove')}]];
        var prefix = ctx + "system/song";

        $(function() {
            var options = {
                url: prefix + "/list2",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                queryParams: queryParams,
				sortName: "createTime",
		        sortOrder: "desc",
                modalName: "曲目",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'songId', 
                    title: '曲目编号'
                },
                {
                    field: 'songName', 
                    title: '曲目名称'
                },
                {
                    field: 'author',
                    title: '作者'
                },
                {
                    field: 'createTime', 
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if('1'==row.addPeriedFlag){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="remove(\'' + row.songId+'\',\''+row.songName+ '\')"><i class="fa fa-minus"></i>移除</a> ');
                        }else{
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="add(\'' + row.songId+'\',\''+row.songName+ '\')"><i class="fa fa-plus"></i>添加</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function queryParams(params) {
			var search = $.table.queryParams(params);
			search.bookId = $("#bookId").val();
			search.preidId = $("#preidId").val();
			return search;
		}
		
		/*字典数据-新增字典*/
		function add(songId,songName) {
		    var preidId = $("#preidId").val();
		    var bookId = $("input[name='bookId']").val()
            	var data =new FormData();
            	 data.append("preidId", preidId);
            	data.append("bookId",bookId);
            	data.append("songId",songId);
            	data.append("songName",songName);
                $.ajax({
                    url: prefix + "/add2",
                    data: data,
                    type: "post",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                    	$.operate.ajaxSuccess(result);
                    }
                })
		}
		/*字典数据-新增字典*/
		function remove(songId,songName) {
		    var preidId = $("#preidId").val();
		    var bookId = $("input[name='bookId']").val()
            	var data =new FormData();
            	 data.append("preidId", preidId);
            	data.append("bookId",bookId);
            	data.append("songId",songId);
            	data.append("songName",songName);
                $.ajax({
                    url: prefix + "/remove2",
                    data: data,
                    type: "post",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                    	$.operate.ajaxSuccess(result);
                    }
                })
		}
    </script>
</body>
</html>